package com.disability_federation.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

/**
 * 生成jwt令牌
 */
public class CreatJWT {
    public static String keySign = "PwRqEI9yUvHm5Ez2pRJlI3Ul17FlSb4Rb4TEzRrgpnid0Nxv79Wc92hzZhBcb6dLcF4zRYCBA1AaNpMpZUWx8zylOuxh1OqIq2CUGSn2tPqoS1USeFPJ3brS5ylCoOgmaPbC0SuDnXosWMiuz2JqAIoWbgQ3kUAsvms3J3dKeBWwJdx6xtnM9oc6vV5hFyCnfZP7pzsGZPoSNAWQ";
    public static Long expireTime = 1000L * 60 * 60 * 24;

    /**
     * 生成jwt
     */
    public static String generateJwt(Map<String, Object> claims) {
        String jwt = Jwts.builder()
                .addClaims(claims)
                .signWith(SignatureAlgorithm.HS256, keySign)
                .setExpiration(new Date(System.currentTimeMillis() + expireTime))
                .compact();
        return jwt;
    }

    public static Claims parseJwt(String jwt) {
        Claims claims = Jwts.parser()
                .setSigningKey(keySign)
                .parseClaimsJws(jwt)
                .getBody();
        return claims;
    }
}
